home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / CUGUK / PROG_TOO / C027B.ZIP / LIBFP / FPMUL.S < prev    next >
Text File  |  1990-03-30  |  2KB  |  119 lines

  1. * Copyright (c) 1988 by Sozobon, Limited.  Author: Johann Ruegg
  2. *
  3. * Permission is granted to anyone to use this software for any purpose
  4. * on any computer system, and to redistribute it freely, with the
  5. * following restrictions:
  6. * 1) No charge may be made other than reasonable charges for reproduction.
  7. * 2) Modified versions must be clearly marked as such.
  8. * 3) The authors are not responsible for any harmful consequences
  9. *    of using this software, even if they result from defects in it.
  10. *
  11. *    fpmul
  12. *
  13.     .globl    _fpmult
  14.     .globl    _fpmul
  15.     .globl    fpmul
  16. fpmul:
  17. _fpmul:
  18. _fpmult:
  19.     move.l    d3,a1        * save d3
  20.     move.l    4(sp),d0
  21.     move.l    8(sp),d1
  22.     move.b    d0,d2
  23.     beq    ret0
  24.     move.b    d1,d3
  25.     beq    ret0
  26.  
  27.     and.b    #$7f,d0
  28.     and.b    #$7f,d1
  29.     eor.b    d2,d3
  30.     bpl    mpos
  31. * result negative
  32.     movem.l    d4-d5,-(sp)
  33.     bsr    _u_mul
  34.     movem.l    (sp)+,d4-d5
  35.     tst.b    d0
  36.     beq    ret0
  37.     move.l    a1,d3        * restore d3
  38.     or.b    #$80,d0
  39.     rts
  40. * result positive
  41. mpos:
  42.     movem.l    d4-d5,-(sp)
  43.     bsr    _u_mul
  44.     movem.l    (sp)+,d4-d5
  45.     move.l    a1,d3        * restore d3
  46.     rts
  47. ret0:
  48.     move.l    a1,d3        * restore d3
  49.     clr.l    d0
  50.     rts
  51.  
  52. _u_mul:
  53.     move.l    d3,a2        * save d3
  54.     move.b    d0,d2
  55.     add.b    d1,d2
  56.     cmp.b    #$40,d2
  57.     bls    underfl
  58.     cmp.b    #$bf,d2
  59.     bhi    overfl
  60.     sub.b    #$40,d2        * result exp
  61.  
  62.     clr.b    d0
  63.     clr.b    d1
  64.     move.w    d0,d3
  65.     mulu.w    d1,d3
  66. *    clr.w    d3    already 0 since low bytes 0
  67.     swap    d3
  68.  
  69.     move.w    d0,d4
  70.     move.w    d1,d5
  71.     swap    d0
  72.     swap    d1
  73.     mulu    d0,d5
  74.     mulu    d1,d4
  75.     add.l    d3,d4    * no carry since d3 <= fe01 && d4 <= fffe0001
  76.     add.l    d4,d5
  77.     bcc    nocar
  78.     move.w    #1,d5
  79.     bra    t1
  80. nocar:
  81.     clr.w    d5
  82. t1:
  83.     swap    d5
  84.  
  85.     mulu    d1,d0
  86.     add.l    d5,d0
  87.     bcc    nocar2
  88.     roxr.l    #1,d0
  89.     addq.b    #1,d2
  90.     bmi    overfl
  91.     bra    norm
  92. nocar2:
  93.     bmi    norm
  94.     add.l    d0,d0    * only need at most 1 shift since started norm AB
  95.     subq.b    #1,d2
  96.     beq    underfl
  97. norm:
  98.     tst.b    d0
  99.     bpl    noround
  100.     add.l    #$80,d0
  101.     bcc    nocar3
  102.     roxr.l    #1,d0
  103.     addq.b    #1,d2
  104.     bmi    overfl
  105. nocar3:
  106. noround:
  107.     move.l    a2,d3        * restore d3
  108.     move.b    d2,d0
  109.     rts
  110.  
  111. underfl:
  112.     move.l    a2,d3        * restore d3
  113.     clr.l    d0
  114.     rts
  115. overfl:
  116.     move.l    a2,d3        * restore d3
  117.     move.l    #$ffffff7f,d0
  118.     rts
  119.